package xcraft.xserver.persistence;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.hibernate.validator.Pattern;

/**
 * 
 * @author AlexM
 *
 */
//@JsonAutoDetect(JsonMethod.NONE)
@Entity(name = "`Planet`")
public class Planet implements Serializable {

	private static final long serialVersionUID = 4550509741131634574L;

	private Integer metal;

	private Integer metalMax;

	private Integer crystal;

	private Integer crystalMax;

	private Integer deuterium;

	private Integer deuteriumMax;

	private Integer matter;

	private Integer energyUsed;

	private Integer energyMax;

	private Integer sectorsUsed;

	private Integer sectorsMax;

	private Integer derbisMetal;
	
	private Integer derbisCrystal;
	
	private String name;
	
	private String diameter;

	private String temperature;

	private Integer galaxy;
	
	private Integer system;
	
	private Integer position;

	public Planet(){}
	public Planet (String id) {
		setId(id);
	}
	
	/**
	 * @return the crystal
	 */
	@Column(name="`crystal`")
	public Integer getCrystal() {
		return crystal;
	}
	
	/**
	 * @param crystal the crystal to set
	 */
	public void setCrystal(Integer crystal) {
		this.crystal = crystal;
	}

	/**
	 * @return the id
	 */
	@Id
	@Pattern(regex="\\[[0-9]+:[0-9]+:[0-9]+\\]")
//	@JsonProperty("location")
	public String getId() {
		return String.format("[%d:%d:%d]", galaxy, system, position);
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		String[] tokens = id.replaceAll("[^0-9:]+", "").split(":");
        galaxy = Integer.valueOf(tokens[0]);
        system = Integer.valueOf(tokens[1]);
        position = Integer.valueOf(tokens[2]);
	}

	/**
	 * @return the metal
	 */
	@Column(name="`metal`")
	public Integer getMetal() {
		return metal;
	}

	/**
	 * @param metal the metal to set
	 */
	public void setMetal(Integer metal) {
		this.metal = metal;
	}

	/**
	 * @return the metalMax
	 */
	@Column(name="`metalMax`")
	public Integer getMetalMax() {
		return metalMax;
	}

	/**
	 * @param metalMax the metalMax to set
	 */
	public void setMetalMax(Integer metalMax) {
		this.metalMax = metalMax;
	}

	/**
	 * @return the crystalMax
	 */
	@Column(name="`crystalMax`")
	public Integer getCrystalMax() {
		return crystalMax;
	}

	/**
	 * @param crystalMax the crystalMax to set
	 */
	public void setCrystalMax(Integer crystalMax) {
		this.crystalMax = crystalMax;
	}

	/**
	 * @return the deuterium
	 */
	@Column(name="`deuterium`")
	public Integer getDeuterium() {
		return deuterium;
	}

	/**
	 * @param deuterium the deuterium to set
	 */
	public void setDeuterium(Integer deuterium) {
		this.deuterium = deuterium;
	}

	/**
	 * @return the deuteriumMax
	 */
	@Column(name="`deuteriumMax`")
	public Integer getDeuteriumMax() {
		return deuteriumMax;
	}

	/**
	 * @param deuteriumMax the deuteriumMax to set
	 */
	public void setDeuteriumMax(Integer deuteriumMax) {
		this.deuteriumMax = deuteriumMax;
	}

	/**
	 * @return the matter
	 */
	@Column(name="`matter`")
	public Integer getMatter() {
		return matter;
	}

	/**
	 * @param matter the matter to set
	 */
	public void setMatter(Integer matter) {
		this.matter = matter;
	}

	/**
	 * @return the energyUsed
	 */
	@Column(name="`energyUsed`")
	public Integer getEnergyUsed() {
		return energyUsed;
	}

	/**
	 * @param energyUsed the energyUsed to set
	 */
	public void setEnergyUsed(Integer energyUsed) {
		this.energyUsed = energyUsed;
	}

	/**
	 * @return the energyMax
	 */
	@Column(name="`energyMax`")
	public Integer getEnergyMax() {
		return energyMax;
	}

	/**
	 * @param energyMax the energyMax to set
	 */
	public void setEnergyMax(Integer energyMax) {
		this.energyMax = energyMax;
	}

	/**
	 * @return the sectorsUsed
	 */
	@Column(name="`sectorsUsed`")
	public Integer getSectorsUsed() {
		return sectorsUsed;
	}

	/**
	 * @param sectorsUsed the sectorsUsed to set
	 */
	public void setSectorsUsed(Integer sectorsUsed) {
		this.sectorsUsed = sectorsUsed;
	}

	/**
	 * @return the sectorsMax
	 */
	@Column(name="`sectorsMax`")
	public Integer getSectorsMax() {
		return sectorsMax;
	}

	/**
	 * @param sectorsMax the sectorsMax to set
	 */
	public void setSectorsMax(Integer sectorsMax) {
		this.sectorsMax = sectorsMax;
	}

	/**
	 * @return the derbisMetal
	 */
	@Column(name="`derbisMetal`")
	public Integer getDerbisMetal() {
		return derbisMetal;
	}

	/**
	 * @param derbisMetal the derbisMetal to set
	 */
	public void setDerbisMetal(Integer derbisMetal) {
		this.derbisMetal = derbisMetal;
	}

	/**
	 * @return the derbisCrystal
	 */
	@Column(name="`derbisCrystal`")
	public Integer getDerbisCrystal() {
		return derbisCrystal;
	}

	/**
	 * @param derbisCrystal the derbisCrystal to set
	 */
	public void setDerbisCrystal(Integer derbisCrystal) {
		this.derbisCrystal = derbisCrystal;
	}

	/**
	 * @return the name
	 */
	@Column(name="`name`")
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the diameter
	 */
	@Column(name="`diameter`")
	public String getDiameter() {
		return diameter;
	}

	/**
	 * @param diameter the diameter to set
	 */
	public void setDiameter(String diameter) {
		this.diameter = diameter;
	}

	/**
	 * @return the temperature
	 */
	@Column(name="`temperature`")
	public String getTemperature() {
		return temperature;
	}

	/**
	 * @param temperature the temperature to set
	 */
	public void setTemperature(String temperature) {
		this.temperature = temperature;
	}

	/**
	 * @return the galaxy
	 */
	@Transient
	public Integer getGalaxy() {
		return galaxy;
	}

	/**
	 * @param galaxy the galaxy to set
	 */
	public void setGalaxy(Integer galaxy) {
		this.galaxy = galaxy;
	}

	/**
	 * @return the system
	 */
	@Transient
	public Integer getSystem() {
		return system;
	}

	/**
	 * @param system the system to set
	 */
	public void setSystem(Integer system) {
		this.system = system;
	}

	/**
	 * @return the position
	 */
	@Transient
	public Integer getPosition() {
		return position;
	}

	/**
	 * @param position the position to set
	 */
	public void setPosition(Integer position) {
		this.position = position;
	}
	
	@Override
	public String toString() {
		return String.format("%s %s", name == null ? "Destroyed Planet" : name, getId());
	}
}

